package com.kobe.game_60;

import java.util.Arrays;

import com.kobe.util.MathUtil;

/**
 * 
 * The arithmetic sequence, 1487, 4817, 8147, in which each of the terms
 * increases by 3330, is unusual in two ways: (i) each of the three terms are
 * prime, and, (ii) each of the 4-digit numbers are permutations of one another.
 * 
 * There are no arithmetic sequences made up of three 1-, 2-, or 3-digit primes,
 * exhibiting this property, but there is one other 4-digit increasing sequence.
 * 
 * What 12-digit number do you form by concatenating the three terms in this
 * sequence?
 * 
 * 
 */
public class _49 {
    public static boolean sameSequnce(int a, int b, int c) {
        char[] charAS = String.valueOf(a).toCharArray();
        char[] charBS = String.valueOf(b).toCharArray();
        char[] charCS = String.valueOf(c).toCharArray();
        Arrays.sort(charAS);
        Arrays.sort(charBS);
        Arrays.sort(charCS);
        for (int i = 0; i < charAS.length; i++) {
            if (!(charAS[i] == charBS[i] && charAS[i] == charCS[i])) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        int a, b, c;
        for (int i = 1000; i <= 3999; i++) {
            a = i;
            b = i + 3330;
            c = i + 6660;
            if (MathUtil.isPrime(a) && MathUtil.isPrime(b)
                    && MathUtil.isPrime(c)) {
                if (sameSequnce(a, b, c)) {
                    System.out.println(a + "" + b + "" + c);
                }
            }
        }
    }
}
